|
RAIS
3.2
|
00001 00027 using System; 00028 using System.Collections.Generic; 00029 using System.Text; 00030 using System.Web.UI; 00031 using System.Web.UI.WebControls; 00032 using System.Xml; 00033 using System.Web.UI.HtmlControls; 00034 using RAIS.Common.UserManagement; 00035 using ExpandedNodes = System.Collections.Generic.Dictionary<string, bool>; 00036 00037 namespace RAIS.UI.Common 00038 { 00042 public class PageManagement 00043 { 00044 /*class ListsInfo 00045 { 00046 public string PageLocation { get; set; } 00047 public ListBox List { get; set; } 00048 public Panel Panel { get; set; } 00049 public bool IsRestoreScroll { get; set; } 00050 public ListsInfo(ListBox list, Panel panel, bool isRestoreScroll, string pageLocation) 00051 { 00052 List = list; 00053 Panel = panel; 00054 IsRestoreScroll = isRestoreScroll; 00055 PageLocation = pageLocation; 00056 } 00057 00058 } 00059 private static List<ListsInfo> scrolableList = new List<ListsInfo>();*/ 00064 public static void TrimTextBoxValues(Control controls) 00065 { 00066 foreach (Control control in controls.Controls) 00067 { 00068 if (control.Controls.Count != 0) 00069 TrimTextBoxValues(control); 00070 if (control is TextBox) 00071 (control as TextBox).Text = (control as TextBox).Text.Trim(); 00072 } 00073 } 00074 00075 public static void SelectTreeNode(TreeNodeCollection collection, string path) 00076 { 00077 foreach (TreeNode value in collection) 00078 if (value.Value == path) 00079 { 00080 value.Select(); 00081 return; 00082 } 00083 } 00084 public static void InitHelpMainMenu(HtmlAnchor helpItem) 00085 { 00086 helpItem.HRef = string.Format("javascript:var popupWin=window.open('{0}','Help','width=600, height=800, menubar=no,location=no,status=no,resizable=yes,scrollbars=yes');popupWin.focus();", 00087 string.Format("help.aspx?context={0}_{1}", helpItem.Page.Session[UI.Common.Constants.HELP_CONTEXT_TAG], "-1")); 00088 } 00089 00090 public static void InitHelpMainMenu(HtmlAnchor helpItem, int dynamicMaskID) 00091 { 00092 helpItem.HRef = string.Format("javascript:var popupWin=window.open('{0}','Help','width=600, height=800, menubar=no,location=no,status=no,resizable=yes,scrollbars=yes');popupWin.focus();", 00093 string.Format("../help.aspx?context={0}_{1}", helpItem.Page.Session[UI.Common.Constants.HELP_CONTEXT_TAG], dynamicMaskID)); 00094 } 00095 00096 public static Panel SetScrolableListBox(ListBox list, Page page, bool restoreScroll) 00097 { 00098 if (page.Request.Browser.Browser != "IE" && page.Request.Browser.Browser != "IE") 00099 return null; 00100 00101 HtmlControl script = new HtmlGenericControl("script"); 00102 script.Attributes["type"] = "text/javascript"; 00103 script.Attributes["src"] = "ScrollableListBox.js"; 00104 page.Header.Controls.Add(script); 00105 Label spanScript = new Label(); 00106 spanScript.Text = "<script language='javascript' type='text/javascript'>Init();</script>"; 00107 page.Controls.Add(spanScript); 00108 00109 /*Panel pan = new Panel(); 00110 Control parent = list.Parent; 00111 int index = parent.Controls.IndexOf(list); 00112 pan.Controls.Add(list); 00113 parent.Controls.AddAt(index, pan); 00114 scrolableList.Add(new ListsInfo(list, pan, restoreScroll, page.Request.Url.AbsoluteUri)); 00115 00116 page.ClientScript.RegisterClientScriptBlock(page.GetType(), "onchange", "<script language='javascript' type='text/jscript'> " + 00117 "function onChange(listID, divID) " + 00118 "{ " + 00119 " var select =document.getElementById(listID); " + 00120 " var div =document.getElementById(divID); " + 00121 " var scrollStep=select.offsetHeight/select.length; " + 00122 " if(div.scrollTop+div.clientHeight-scrollStep<scrollStep*select.selectedIndex) " + 00123 " div.scrollTop=div.scrollTop+scrollStep; " + 00124 " else if(div.scrollTop>scrollStep*select.selectedIndex) " + 00125 " div.scrollTop=div.scrollTop-scrollStep+2; " + 00126 "}; " + 00127 "</script> "); 00128 page.PreRender += new EventHandler(page_LoadComplete); 00129 string listClientID = list.ClientID.Replace(' ', '_'); 00130 string divClientID = pan.ClientID.Replace(' ', '_'); 00131 Label spanScript = new Label(); 00132 spanScript.Style["display"] = "none"; 00133 spanScript.Text = "<script language='javascript' type='text/javascript'>"; 00134 if (restoreScroll) 00135 spanScript.Text = spanScript.Text + 00136 "setPosition('" + listClientID + "', '" + divClientID + "'); " + 00137 "function setPosition(selectId, divId){ " + 00138 "var select =document.getElementById(selectId); " + 00139 "var div =document.getElementById(divId); " + 00140 "var scrollStep=select.offsetHeight/select.length; " + 00141 "div.scrollTop=select.selectedIndex*scrollStep; " + 00142 "}; "; 00143 spanScript.Text = spanScript.Text + 00144 "setSize('" + listClientID + "', '" + divClientID + "'); " + 00145 "function setSize(selectId, divId){ " + 00146 "var select =document.getElementById(selectId); " + 00147 "var div =document.getElementById(divId); " + 00148 "if(select.offsetWidth<div.offsetWidth) " + 00149 " select.style.width=(div.offsetWidth)+'px'; " + 00150 "if(select.offsetWidth<div.offsetWidth) " + 00151 " select.style.height=(div.offsetHeight)+'px'; " + 00152 "if(select.offsetHeight==div.offsetHeight) " + 00153 " select.style.overflowX='hidden';" + 00154 "if(select.offsetHeight==div.offsetHeight) " + 00155 " select.style.overflowY='hidden';" + 00156 "}; " + 00157 "</script>"; 00158 page.Controls.Add(spanScript);*/ 00159 00160 return null; 00161 } 00162 00163 /*static void page_LoadComplete(object sender, EventArgs e) 00164 { 00165 List<string> listIds = new List<string>(); 00166 foreach (ListsInfo scrollList in scrolableList) 00167 { 00168 if (!sender.Equals(scrollList.Panel.Page) || scrollList.PageLocation != ((Page)sender).Request.Url.AbsoluteUri || listIds.Contains(scrollList.List.ClientID)) continue; 00169 listIds.Add(scrollList.List.ClientID); 00170 ListBox listBox = scrollList.List; 00171 Panel panel = scrollList.Panel; 00172 string listClientID = listBox.ClientID.Replace(' ', '_'); 00173 string divClientID = panel.ClientID.Replace(' ', '_'); 00174 00175 panel.Style["overflow"] = "auto"; 00176 panel.Style["width"] = (new Unit(listBox.Width.Value - 3)).ToString(); 00177 panel.Style["height"] = (new Unit(listBox.Height.Value - 3)).ToString(); 00178 panel.CssClass = "scrollableDiv"; 00179 if (listBox.Items.Count != 0) 00180 { 00181 listBox.Style["width"] = "auto"; 00182 listBox.Style["height"] = "auto"; 00183 listBox.Style["overflow"] = "visible"; 00184 listBox.Attributes["onchange"] = "onChange('" + listClientID + "','" + divClientID + "');"; 00185 if (listBox.Items.Count == 1) 00186 listBox.Rows = 2; 00187 else 00188 listBox.Rows = listBox.Items.Count; 00189 } 00190 } 00191 scrolableList.Clear(); 00192 }*/ 00193 00194 #region Public static methods 00195 00199 public static void InitializeListboxTooltips(ListBox listBox) 00200 { 00201 InitializeItemsTooltips(listBox.Items); 00202 } 00207 public static void InitializeItemsTooltips(ListItemCollection items) 00208 { 00209 foreach (ListItem item in items) 00210 { 00211 item.Attributes.Add("title", item.Text); 00212 } 00213 } 00219 public static void InitializePage(Page page, TreeView tree) 00220 { 00221 InitializePage(page, tree, false); 00222 } 00228 public static void InitializePage(Page page, TreeView tree, bool designMode) 00229 { 00230 // if (!page.IsPostBack) 00231 { 00232 UserData currentUser = (UserData)page.Session[UI.Common.Constants.CURRENT_USER_TAG]; 00233 00234 if (currentUser != null) 00235 { 00236 XmlDocument siteMapDoc = RAIS.ApplicationLogicLayer.UserManagement.GetSiteMapByUser(currentUser, designMode); 00237 00238 bool siteMapInitialized = UI.Common.UserManagement.InitializeSiteMapTree(tree, siteMapDoc); 00239 00240 UI.Common.Localisation.TranslatePage(page); 00241 00242 if (siteMapInitialized) 00243 { 00244 ExpandedNodes expandedNodes = (ExpandedNodes)page.Session[UI.Common.Constants.SITE_MAP_EXPANSION_STATES]; 00245 string selectedNodePath = (string)page.Session[UI.Common.Constants.SITE_MAP_SELECTED_NODE]; 00246 00247 tree.SelectedNodeStyle.ForeColor = System.Drawing.Color.DarkRed; 00248 tree.SelectedNodeStyle.Font.Underline = false; 00249 00250 RAIS.UI.Common.UserManagement.RestoreSiteMapExtensionState(tree.Nodes, expandedNodes, selectedNodePath); 00251 00252 } 00253 page.Session[UI.Common.Constants.HELP_CONTEXT_TAG] = GetContext(page, siteMapDoc, tree); 00254 00255 } 00256 UI.Common.UserManagement.ApplyAccessRights(page); 00257 } 00258 //else 00259 //{ 00260 // string selectedNodePath = (string)page.Session[UI.Common.Constants.SITE_MAP_SELECTED_NODE]; 00261 // RAIS.UI.Common.UserManagement.RestoreSelectedNode(tree.Nodes, selectedNodePath); 00262 //} 00263 if (page.Session["IsRightToLeft"] != null && (bool)page.Session["IsRightToLeft"]) 00264 { 00265 page.Form.Attributes["dir"] = "rtl"; 00266 foreach (Control control in page.Header.Controls) 00267 if (control is HtmlLink && ((HtmlLink)control).Href.IndexOf("rais1.css") != -1) 00268 ((HtmlLink)control).Href = ((HtmlLink)control).Href.Replace("rais1.css", "rais1-rtl.css"); 00269 } 00270 //HideDisabledMenuItems(page); 00271 } 00272 00273 private static string GetContext(Page page, XmlDocument siteMapDoc, TreeView tree) 00274 { 00275 XmlNode categoryNode; 00276 XmlNode subCategoryNode; 00277 XmlNode maskNode; 00278 00279 string categoryId; 00280 string subCategoryId; 00281 string maskId; 00282 00283 string currLang = ((UserData)page.Session[UI.Common.Constants.CURRENT_USER_TAG]).Language; 00284 string url = page.Request.AppRelativeCurrentExecutionFilePath; 00285 00286 string categoryName = (string)page.Session[UI.Common.Constants.SELECTED_CATEGORY_TAG]; 00287 00288 categoryNode = siteMapDoc.SelectSingleNode(string.Format("//SiteMap/Category[@Name='{0}']", categoryName)); 00289 if (categoryNode == null) 00290 return GetContextByURL(url, siteMapDoc, currLang); 00291 categoryId = categoryNode.Attributes["ID"].Value; 00292 00293 if (tree.SelectedNode == null || tree.SelectedNode.Parent == null) 00294 return GetContextByURL(url, siteMapDoc, currLang); 00295 00296 //string selectedNodeParentEnglish = ApplicationLogicLayer.Localisation.Translate(tree.SelectedNode.Parent.Value, tree.ID, currLang, 00297 // RAIS.Common.Constants.DEFAULT_LANGUAGE); // causes problems, since reverse translation is not unique 00298 00299 string selectedNodeParentEnglish = tree.SelectedNode.Parent.ImageToolTip; // used to get the untranslated node text 00300 00301 subCategoryNode = categoryNode.SelectSingleNode(string.Format("//SiteMap/Category[@Name='{0}']/Subcategory[@Name='{1}']", categoryName, selectedNodeParentEnglish)); 00302 if (subCategoryNode == null) 00303 return GetContextByURL(url, siteMapDoc, currLang); 00304 subCategoryId = subCategoryNode.Attributes["ID"].Value; 00305 00306 //string selectedNodeEnglish = ApplicationLogicLayer.Localisation.Translate(tree.SelectedNode.Text, tree.ID, currLang, 00307 // RAIS.Common.Constants.DEFAULT_LANGUAGE); // causes problems, since reverse translation is not unique 00308 00309 string selectedNodeEnglish = tree.SelectedNode.ImageToolTip; // used to get the untranslated node text 00310 00311 maskNode = subCategoryNode.SelectSingleNode(string.Format("//SiteMap/Category[@Name='{0}']/Subcategory[@Name='{1}']/Mask[@Name='{2}']", categoryName, selectedNodeParentEnglish, selectedNodeEnglish)); 00312 00313 if (maskNode == null) 00314 return GetContextByURL(url, siteMapDoc, currLang); 00315 else 00316 { 00317 string reference=maskNode.Attributes["Reference"].Value; 00318 if(reference.IndexOf(url, StringComparison.CurrentCultureIgnoreCase) == -1 00319 && reference.IndexOf("Dynamic Masks", StringComparison.CurrentCultureIgnoreCase) == -1) 00320 return GetContextByURL(url, siteMapDoc, currLang); 00321 } 00322 00323 maskId = maskNode.Attributes["ID"].Value; 00324 00325 return string.Format("{0}_{1}_{2}_{3}", categoryId, subCategoryId, maskId, RAIS.ApplicationLogicLayer.Localisation.SupportedLanguages[currLang].ID); 00326 } 00327 00328 private static string GetContextByURL(string url, XmlDocument siteMapDoc, string currLang) 00329 { 00330 string categoryId="-1"; 00331 string subCategoryId="-1"; 00332 string maskId="-1"; 00333 00334 XmlNode node = siteMapDoc.SelectSingleNode(string.Format("//SiteMap/Category/Subcategory/Mask[@Reference='{0}']", url)); 00335 00336 if (node == null) 00337 { 00338 ApplicationLogicLayer.UserManagement.GetMaskByReference(url, out categoryId, out subCategoryId, out maskId); 00339 if (categoryId == "-1") 00340 return ""; 00341 } 00342 else 00343 { 00344 maskId = node.Attributes["ID"].Value; 00345 subCategoryId = node.ParentNode.Attributes["ID"].Value; 00346 categoryId = node.ParentNode.ParentNode.Attributes["ID"].Value; 00347 } 00348 00349 return string.Format("{0}_{1}_{2}_{3}", categoryId, subCategoryId, maskId, RAIS.ApplicationLogicLayer.Localisation.SupportedLanguages[currLang].ID); 00350 } 00351 00352 public static void HideDisabledMenuItems(Page page) 00353 { 00354 page.ClientScript.RegisterStartupScript(page.GetType(), "hideDisabladMenu", 00355 "<script language='javascript' type='text/jscript'> " + 00356 "var menuItems =document.getElementsByTagName('a');" + 00357 "for (i=0;i<menuItems.length;i++)" + 00358 " if(menuItems[i].parentNode.parentNode.parentNode.parentNode.parentNode.className=='h_mnu_01' && menuItems[i].disabled)" + 00359 " menuItems[i].parentNode.style.display='none';" + 00360 "</script> "); 00361 } 00368 public static void InitializePageTreeForCategory(Page page, TreeView tree, string category) 00369 { 00370 InitializePageTreeForCategory(page, tree, category, false); 00371 } 00378 public static void InitializePageTreeForCategory(Page page, TreeView tree, string category, bool designMode) 00379 { 00380 page.Session[UI.Common.Constants.SELECTED_CATEGORY_TAG] = category; 00381 page.Session[UI.Common.Constants.SITE_MAP_SELECTED_NODE] = null; 00382 00383 InitializePage(page, tree, designMode); 00384 CollapseTree(page, tree); 00385 //tree.SelectedNodeStyle.ForeColor = tree.ParentNodeStyle.ForeColor; 00386 tree.SelectedNodeStyle.ForeColor = System.Drawing.Color.DarkRed; 00387 tree.SelectedNodeStyle.Font.Underline = false; 00388 } 00389 00390 private static void CollapseTree(Page page, TreeView tree) 00391 { 00392 if (!page.IsPostBack && (page.Request.Url.AbsolutePath.IndexOf("Admin", StringComparison.CurrentCultureIgnoreCase) != -1 || 00393 page.Request.Url.AbsolutePath.IndexOf("Input", StringComparison.CurrentCultureIgnoreCase) != -1 || 00394 page.Request.Url.AbsolutePath.IndexOf("Query", StringComparison.CurrentCultureIgnoreCase) != -1 || 00395 page.Request.Url.AbsolutePath.IndexOf("RegSys", StringComparison.CurrentCultureIgnoreCase) != -1 || 00396 page.Request.Url.AbsolutePath.IndexOf("Statistics", StringComparison.CurrentCultureIgnoreCase) != -1 || 00397 page.Request.Url.AbsolutePath.IndexOf("Tools", StringComparison.CurrentCultureIgnoreCase) != -1)) 00398 tree.CollapseAll(); 00399 } 00400 00401 public static bool GetShowProtectors(Page page) 00402 { 00403 if (page.Session["ShowProtectors"] == null) 00404 return false; 00405 else 00406 return (bool)page.Session["ShowProtectors"]; 00407 } 00408 00409 public static void SetShowProtectors(Page page, bool showProtectors) 00410 { 00411 page.Session["ShowProtectors"] = showProtectors; 00412 } 00413 00414 public static bool GetShowEvaluators(Page page) 00415 { 00416 if (page.Session["ShowEvaluators"] == null) 00417 return false; 00418 else 00419 return (bool)page.Session["ShowEvaluators"]; 00420 } 00421 00422 public static void SetShowEvaluators(Page page, bool showEvaluators) 00423 { 00424 page.Session["ShowEvaluators"] = showEvaluators; 00425 } 00426 00427 public static void ShowHideSystemFields(Page page, bool show) 00428 { 00429 page.Session["IsVisibleSystemFields"] = show; 00430 } 00431 00432 public static bool IsVisibleSystemFields(Page page) 00433 { 00434 if (page.Session["IsVisibleSystemFields"] == null) 00435 return false; 00436 return (bool)page.Session["IsVisibleSystemFields"]; 00437 } 00438 00439 public static Dictionary<string, string> GetRenamedNodes(Page page) 00440 { 00441 if (page.Session["RenamedNodes"] == null) 00442 return new Dictionary<string, string>(); 00443 else 00444 return (Dictionary<string, string>)page.Session["RenamedNodes"]; 00445 } 00446 00447 public static void SetRenamedNodes(Page page, string nodeName, string newName) 00448 { 00449 Dictionary<string, string> renamedNodes = GetRenamedNodes(page); 00450 00451 if (newName == string.Empty) 00452 { 00453 if (renamedNodes.ContainsKey(nodeName)) 00454 renamedNodes.Remove(nodeName); 00455 } 00456 else 00457 { 00458 if (renamedNodes.ContainsKey(nodeName)) 00459 renamedNodes[nodeName] = newName; 00460 else 00461 renamedNodes.Add(nodeName, newName); 00462 } 00463 00464 page.Session["RenamedNodes"] = renamedNodes; 00465 } 00466 00467 #endregion 00468 } 00469 }